﻿using System;
using System.Threading.Tasks;

namespace IOP.Orleans.MessageHub
{
    /// <summary>
    /// 消息服务接口
    /// </summary>
    public interface IMessageHubService : IOrleansService
    {
        /// <summary>
        /// 注册消息监听者
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="customMessageHandle"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        Task<IMessageDispatcher> RegistObserver<TMessage>(Func<TMessage, Task> customMessageHandle, string prefix) where TMessage : class;
        /// <summary>
        /// 发布消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="message"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        Task PublishMessage<TMessage>(TMessage message, string prefix) where TMessage : class;
        /// <summary>
        /// 注册一个监听者开始监听的事件
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="prefix"></param>
        IMessageDispatcher RegistObserverBeginListenedEvent(Func<IMessageDispatcher, Task> handle, string prefix);
        /// <summary>
        /// 注册一个监听者开始监听的事件
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="prefix"></param>
        IMessageDispatcher RegistObserverBeginListenedEvent(IMessageDispatcher dispatcher, Func<IMessageDispatcher, Task> handle);
        /// <summary>
        /// 注册一个监听者停止监听的事件
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        IMessageDispatcher RegistObserverAbortListenedEvent(Func<IMessageDispatcher, Task> handle, string prefix);
        /// <summary>
        /// 注册一个监听者停止监听的事件
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        IMessageDispatcher RegistObserverAbortListenedEvent(IMessageDispatcher dispatcher, Func<IMessageDispatcher, Task> handle);
        /// <summary>
        /// 注册一个健康检查函数
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        IMessageDispatcher RegistHealthCheckHandle(Func<byte[], Task> handle, string prefix);
        /// <summary>
        /// 注册一个健康检查函数
        /// </summary>
        /// <param name="dispatcher"></param>
        /// <param name="handle"></param>
        /// <returns></returns>
        IMessageDispatcher RegistHealthCheckHandle(IMessageDispatcher dispatcher, Func<byte[], Task> handle);
    }
}
